# 安装并加载所需的包
library(readxl)
library(lattice)
library(BSDA)

# 手机续航时间数据
battery <- c(20.2, 19.4, 18.6, 18.2, 19.8, 21.4, 18.2, 19.8, 17.4, 19.4, 21.4, 19.0, 19.0, 17.0,
             23.0, 22.6, 21.4, 20.2, 22.6, 20.2, 21.4, 20.2, 18.2, 20.2, 19.0, 19.8, 19.8, 20.6,
             20.6, 18.6, 19.0, 21.4, 20.6, 21.8, 19.4, 19.8, 21.8, 19.4, 17.4, 20.2, 19.8, 17.8,
             17.4, 19.8, 20.2, 19.0, 20.2, 18.2, 21.0, 19.8)

# 读取红楼梦虚词词频统计数据
hlm <- read_excel("C://Users//86189//Desktop//CodeOfGitee//r-code//2207124039_毛若沣_05//红楼梦虚词词频统计.xls")

# 药品试验数据
x <- c(43, 55, 49, 64, 59, 49, 57, 54, 55, 48)
y <- c(50, 59, 55, 60, 58, 54, 56, 53, 61, 51)

# 影视数据
movie <- read_excel("C://Users//86189//Desktop//CodeOfGitee//r-code//2207124039_毛若沣_05//top250.xlsx")

# 手机续航时间的区间估计
sdb <- sd(battery)
z.test(x = battery, sigma.x = sdb, conf.level = 0.95)

# 红楼梦虚词使用习惯分析
freqx <- hlm$之[1:80]
freqy <- hlm$之[81:120]
t.test(freqx, freqy, var.equal = TRUE, conf.level = 0.95)

# 手机续航时间的假设检验
z.test(battery, mu = 20, sigma.x = 0.8, conf.level = 0.95)

# 红楼梦不同章节假设检验
t.test(freqx, freqy, var.equal = FALSE, conf.level = 0.95)

# 成对数据t检验
t.test(x, y, paired = TRUE, alternative = "two.sided", conf.level = 0.95)

# 两个以上的样本，方差分析
# 确保score和nation是movie数据框中的列名
summary(aov(score ~ nation, data = movie))
